//
//  YQMainTabBar.m
//  industry
//
//  Created by 王雅强 on 2021/1/21.
//  Copyright © 2021 Haier. All rights reserved.
//

#import "YQMainTabBar.h"

@implementation YQMainTabBar

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.translucent = NO;
        
        CALayer * layer = self.layer;
////        CALayer * layer1 = [[CALayer alloc]initWithLayer:layer];
//
//
//        layer.cornerRadius = 12;
////        self.clipsToBounds = true;
////        layer.borderColor = [UIColor redColor].CGColor;
        layer.shadowColor = [UIColor colorWithHex:0x000000 alpha:0.04].CGColor;
        layer.shadowOffset = CGSizeMake(0,-2);
        layer.shadowOpacity = 1;
        layer.shadowRadius = 10;
        self.backgroundImage = [UIImage imageWithColor1x1_au:[UIColor whiteColor]];
//        [self addShadowToView:view1 withOpacity:1.0 shadowRadius:10 andCornerRadius:12];
        
      
        
    }
    return self;
}



    /*
     周边加阴影，并且同时圆角
     */
- (void)addShadowToView:(UIView *)view
                withOpacity:(float)shadowOpacity
               shadowRadius:(CGFloat)shadowRadius
            andCornerRadius:(CGFloat)cornerRadius{
         //shadow
        CALayer *shadowLayer = [CALayer layer];
        shadowLayer.frame = view.layer.frame;
        
        shadowLayer.shadowColor = [UIColor colorWithHex:0x000000 alpha:0.04].CGColor;//shadowColor阴影颜色
        shadowLayer.shadowOffset = CGSizeMake(0, -2);//shadowOffset阴影偏移，默认(0, -3),这个跟shadowRadius配合使用
        shadowLayer.shadowOpacity = shadowOpacity;//0.8;//阴影透明度，默认0
        shadowLayer.shadowRadius = shadowRadius;//8;//阴影半径，默认3
        
        //路径阴影
        UIBezierPath *path = [UIBezierPath bezierPath];
        
        float width = shadowLayer.bounds.size.width;
        float height = shadowLayer.bounds.size.height;
        float x = shadowLayer.bounds.origin.x;
        float y = shadowLayer.bounds.origin.y;
        
        CGPoint topLeft      = shadowLayer.bounds.origin;
        CGPoint topRight     = CGPointMake(x + width, y);
        CGPoint bottomRight  = CGPointMake(x + width, y + height);
        CGPoint bottomLeft   = CGPointMake(x, y + height);
        
        CGFloat offset = -1.f;
        [path moveToPoint:CGPointMake(topLeft.x - offset, topLeft.y + cornerRadius)];
        [path addArcWithCenter:CGPointMake(topLeft.x + cornerRadius, topLeft.y + cornerRadius) radius:(cornerRadius + offset) startAngle:M_PI endAngle:M_PI_2 * 3 clockwise:YES];
        [path addLineToPoint:CGPointMake(topRight.x - cornerRadius, topRight.y - offset)];
        [path addArcWithCenter:CGPointMake(topRight.x - cornerRadius, topRight.y + cornerRadius) radius:(cornerRadius + offset) startAngle:M_PI_2 * 3 endAngle:M_PI * 2 clockwise:YES];
        [path addLineToPoint:CGPointMake(bottomRight.x + offset, bottomRight.y - cornerRadius)];
        [path addArcWithCenter:CGPointMake(bottomRight.x - cornerRadius, bottomRight.y - cornerRadius) radius:(cornerRadius + offset) startAngle:0 endAngle:M_PI_2 clockwise:YES];
        [path addLineToPoint:CGPointMake(bottomLeft.x + cornerRadius, bottomLeft.y + offset)];
        [path addArcWithCenter:CGPointMake(bottomLeft.x + cornerRadius, bottomLeft.y - cornerRadius) radius:(cornerRadius + offset) startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
        [path addLineToPoint:CGPointMake(topLeft.x - offset, topLeft.y + cornerRadius)];
        
        //设置阴影路径
        shadowLayer.shadowPath = path.CGPath;
        
         //cornerRadius
        view.layer.cornerRadius = cornerRadius;
        view.layer.masksToBounds = YES;
        view.layer.shouldRasterize = YES;
        view.layer.rasterizationScale = [UIScreen mainScreen].scale;
        
        [view.superview.layer insertSublayer:shadowLayer below:view.layer];
}
@end
